<template>

  <div>
    <div v-if="mode===0">
      <el-button type="primary" plain @click="count2">Statistics</el-button>
    </div>
    <div v-if="mode===1">

    </div>
    <div v-if="mode===2">

    </div>
    <!--统计分店日活-->
    <el-dialog
      title="Statistics"
      :visible.sync="count2Visible"
      width="50%"
    >
      <el-row justify="center" type="flex">
        <template>
          <el-table
            :data="tableData2"
            style="width: 90%">
            <el-table-column
              prop="order"
              label="今日订单"
            >
            </el-table-column>
            <el-table-column
              prop="success"
              label="今日成交"
            >
            </el-table-column>
            <el-table-column
              prop="user"
              label="今日用户"
            >
            </el-table-column>
            <el-table-column
              prop="income"
              label="今日收入"
            >
            </el-table-column>
          </el-table>
        </template>
      </el-row>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="count2Visible = false">Confirm</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
    export default {
        name: "GDFunctionBranchButton",
      props:["mode"],
      data(){
        return{
          count2Visible:false,
        }
      },
      methods:{
        count2(){
          this.count2Visible=true;
        }
      },
      computed: {
        tableData2(){
          const list=this.api.orderList;
          const date=new Date().toLocaleDateString();
          let order=0,success=0,income=0,user=new Set();
          for (const listElement of list) {
            if(listElement.branch===this.$store.state.branch){
              const itemDate=new Date(listElement.date).toLocaleDateString();
              if(itemDate===date){
                order++;
                if(listElement.status==='success'){
                  success++;
                  income+=parseInt(listElement.price.substr(1));
                }
                user.add(listElement.tUser);
              }
            }

          }
          return [{
            order:order,
            success:success,
            user:user.size,
            income:income
          }]
        }
      }
    }
</script>

<style scoped>

</style>
